<template>
  <div class="dashboard-container">
    <!-- 粒子背景元素 -->
    <div class="particles">
      <div v-for="i in 30" :key="i" class="particle" :style="particleStyle(i)"></div>
    </div>

    <!-- 欢迎标题部分保持不变 -->
    <div class="welcome-section">
      <h1>欢迎使用进销存管理系统 <span class="welcome-emoji">👋</span>
        <span>
          <el-button type="danger" size="small" @click="logout" icon="el-icon-delete">退出</el-button>
        </span>
      </h1>

      <p class="welcome-subtitle">请选择您要操作的功能模块</p>
      <div class="decoration-line"></div>
    </div>

    <!-- 第一行4个图标 -->
    <div class="img-row">
      <router-link to="/salesOrder" class="img-link">
        <img src="@/assets/images/salesOrder.png" alt="销售订单" class="original-size-img">
        <p class="img-label">销售订单</p>
      </router-link>
      <router-link to="/buyOrder" class="img-link">
        <img src="@/assets/images/buyOrder.png" alt="采购订单" class="original-size-img">
        <p class="img-label">采购订单</p>
      </router-link>
      <router-link to="/in" class="img-link">
        <img src="@/assets/images/in.png" alt="入库管理" class="original-size-img">
        <p class="img-label">入库管理</p>
      </router-link>
      <router-link to="/productSearch" class="img-link">
        <img src="@/assets/images/productSearch.png" alt="产品查询" class="original-size-img">
        <p class="img-label">产品查询</p>
      </router-link>
    </div>

    <!-- 第二行4个图标 -->
    <div class="img-row">
      <router-link to="/out" class="img-link">
        <img src="@/assets/images/out.png" alt="出库管理" class="original-size-img">
        <p class="img-label">出库管理</p>
      </router-link>
      <router-link to="/salesReceipt" class="img-link">
        <img src="@/assets/images/salesReceipt.png" alt="销售收款" class="original-size-img">
        <p class="img-label">销售收款</p>
      </router-link>
      <router-link to="/cus" class="img-link">
        <img src="@/assets/images/cus.png" alt="客户管理" class="original-size-img">
        <p class="img-label">客户管理</p>
      </router-link>
      <router-link to="/supplier" class="img-link">
        <img src="@/assets/images/supplier.png" alt="供应商管理" class="original-size-img">
        <p class="img-label">供应商管理</p>
      </router-link>
    </div>

    <!-- 卡片部分保持不变 -->
    <el-card class="box-card more-options-card">
      <div class="card-header">
        <i class="el-icon-more-outline card-icon"></i>
        <span>更多详情:</span>
      </div>
      <router-link to="/emp">
        <div class="card-item">
          <i class="el-icon-user"></i>
          <span>职员管理</span>
        </div>
      </router-link>
      <router-link to="/depart">
        <div class="card-item">
          <i class="el-icon-office-building"></i>
          <span>部门管理</span>
        </div>
      </router-link>
    </el-card>

    <!-- 页脚部分保持不变 -->
    <div class="footer-decoration">
      <div class="footer-wave"></div>
      <p class="footer-text">© 2023 管理系统 | 当前用户: {{ name }}</p>
    </div>
  </div>
</template>

<script>
import router from '@/router';
import { mapGetters } from 'vuex'

export default {
  name: 'Dashboard',
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  methods: {
    particleStyle(i) {
      const size = Math.random() * 10 + 5;
      return {
        width: `${size}px`,
        height: `${size}px`,
        left: `${Math.random() * 100}%`,
        top: `${Math.random() * 100}%`,
        backgroundColor: `hsla(${Math.random() * 60 + 200}, 80%, 70%, ${Math.random() * 0.3 + 0.2})`,
        animationDelay: `${Math.random() * 5}s`,
        animationDuration: `${Math.random() * 15 + 10}s`,
        transform: `scale(${Math.random() * 0.5 + 0.5})`
      };
    },
    logout() {
      this.$confirm('确认退出登录吗？')
        .then(() => {
          localStorage.removeItem('token');
          this.$message.success('退出成功');
          router.push('/login');
        })
        .catch(() => {
          this.$message.info('已取消');
        });
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-container {
  margin: 30px 100px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);

  .particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;

    .particle {
      position: absolute;
      border-radius: 50%;
      animation: float 15s infinite linear;
      filter: blur(1px);
    }
  }

  @keyframes float {
    0% {
      transform: translateY(100vh) scale(0.5);
      opacity: 0;
    }

    10% {
      opacity: 0.5;
    }

    90% {
      opacity: 0.5;
    }

    100% {
      transform: translateY(-20vh) scale(1.2);
      opacity: 0;
    }
  }

  .welcome-section {
    text-align: center;
    margin-bottom: 40px;
    position: relative;
    z-index: 1;

    h1 {
      font-size: 28px;
      color: #333;
      margin-bottom: 10px;
      text-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);

      .welcome-emoji {
        font-size: 32px;
        vertical-align: middle;
      }
    }

    .welcome-subtitle {
      font-size: 16px;
      color: #185d85;
      margin-bottom: 15px;
    }

    .decoration-line {
      width: 100px;
      height: 3px;
      background: linear-gradient(to right, #409EFF, #67C23A);
      margin: 0 auto;
      border-radius: 3px;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
  }

  .img-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
    flex-wrap: nowrap;
    padding: 0 50px;
    position: relative;
    z-index: 1;

    .img-link {
      display: flex;
      flex-direction: column;
      align-items: center;
      text-decoration: none;
      transition: all 0.3s;
      flex: 0 0 20%;
      max-width: 20%;

      &:hover {
        transform: translateY(-5px);

        .original-size-img {
          filter: drop-shadow(0 5px 10px rgba(64, 158, 255, 0.3));
        }
      }
    }

    .original-size-img {
      width: 60px;
      height: 60px;
      transition: all 0.3s;

      &:hover {
        transform: scale(1.1);
      }
    }

    .img-label {
      margin-top: 10px;
      color: #333;
      font-size: 14px;
      font-weight: 500;
      text-align: center;
      width: 100%;
    }
  }

  .box-card {
    width: 480px;
    margin: 30px auto;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    position: relative;
    z-index: 1;
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(5px);

    &.more-options-card {
      .card-header {
        display: flex;
        align-items: center;
        margin-bottom: 15px;

        .card-icon {
          font-size: 20px;
          margin-right: 10px;
          color: #409EFF;
        }

        span {
          font-weight: bold;
          color: #333;
        }
      }

      .card-item {
        padding: 10px 15px;
        margin: 5px 0;
        border-radius: 6px;
        transition: all 0.3s;
        display: flex;
        align-items: center;

        &:hover {
          background-color: #f5f7fa;
          transform: translateX(5px);
          box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        i {
          margin-right: 10px;
          color: #67C23A;
        }

        span {
          color: #606266;
        }
      }
    }
  }

  .footer-decoration {
    margin-top: 50px;
    text-align: center;
    position: relative;
    z-index: 1;

    .footer-wave {
      height: 10px;
      background: linear-gradient(90deg, transparent, #409EFF, #67C23A, transparent);
      opacity: 0.3;
      margin-bottom: 15px;
      border-radius: 5px;
    }

    .footer-text {
      color: #909399;
      font-size: 12px;
    }
  }
}
</style>